//加载公共样式
require('../../assets/css/index.less')

//服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'

let dom = require('../../utils/dom')
const request = require('../../utils/request')

//字体图标
require('../../assets/fonts/iconfont.css')
//加载自己的样式
require('./play.less')

window.onload = () => {
    const player = document.querySelector('#player')
    const fragments = JSON.parse(localStorage.getItem('fragments'))
    const pre = document.querySelector('#pre')
    const pause = document.querySelector('#pause')
    const play1 = document.querySelector('#play1')
    const next = document.querySelector('#next')
    const currIndex = document.querySelector('#currIndex')
    const currLength = document.querySelector('#currLength')
    const modle = document.querySelector('#modle')
    const palyBtn = document.querySelector('#palyBtn')
    const backBtn = document.querySelector('#backBtn')
    const titleText = document.querySelector('#title')

    console.log(fragments);
    let index = 0
    let num = 0
    let length = fragments.length
    


    function play() {
        player.src = API + fragments[index].videoUrl
        currIndex.textContent = index + 1
        currLength.textContent = length
        player.addEventListener('canplay', function () {
            player.play()
        })
    }
    play()

    next.addEventListener('click', function () {
        if (index < length - 1) {
            index++

            play()
        } else {
            console.log('后面没了');
        }
    })

    pre.addEventListener('click', function () {
        if (index > 0) {
            index--
            play()
        } else {
            console.log('已经是第一页了');
        }
    })

    pause.addEventListener('click', function () {
        play1.style.display = 'block'
        pause.style.display = 'none'
        player.pause()
        modle.style.display = 'block'
    })

    play1.addEventListener('click', function () {
        play1.style.display = 'none'
        pause.style.display = 'block'
        player.play()
    })
    palyBtn.addEventListener('click', function () {
        modle.style.display = 'none'
        player.play()
        play1.style.display = 'none'
        pause.style.display = 'block'
    })

    backBtn.addEventListener('click', function () {
        history.go(-1)
    })



}
